<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>列表循环渲染</title>
  </head>
  <body>
    <script src="https://unpkg.com/vue@next"></script>

    <div id="root"></div>

    <script>
      const app = Vue.createApp({
        data() {
          return {
              listArr:["hello", "yunmu", "teacher"],
              listObj:{
                  firstName:"yun",
                  lastName:"mu",
                  job:"teacher"
              }
          };
        },

        methods:{
            handleAddBtnClick(){ 
                // 使用数组的变更函数 push pop unshift shift reverse sort splice
                //this.listArr.push("hello");
                //this.listArr.pop();
                //this.listArr.unshift("study");
                //this.listArr.shift();
                this.listArr.reverse();
            }
        },

        template: `
                <div>
                    <p v-for="(item, index) in listObj" :key="index">{{item}} --- {{index}}</p>
                    <button @click="handleAddBtnClick">增加</button>    
                </div>
            `,
        //template: `
        //        <div>
        //            <p v-for="(value, key, index) in listObj">{{value}} --- {{key}} --- {{index}}</p>    
        //        </div>
        //    `,
      });

      const vm = app.mount("#root");
    </script>
  </body>
</html>
